<template>
  <router-layout>
    <Nodata v-if="isNoData"></Nodata>
    <div v-else class="home">
      <div class="swipe-box">
        <van-swipe :autoplay="3000">
          <van-swipe-item v-for="(image, index) in images" :key="index">
            <div class="img-box">
              <img style="width:100%" :src="image.banner_path">
            </div>
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="list-box">
        <div class="list van-hairline--bottom"
          v-for="(item, index) in dataList" :key="index" @click="openLink(item)">
          <div class="content-box fn-clear">
            <div class="img-box">
              <img :src="item.file_path" alt>
            </div>
            <div class="text-box">
              <p>{{ item.organization_name }}</p>
              <div class="other-text">
                <span v-if="item.director" class="text-content">负责人: {{ item.director }}</span>
                <span v-if="item.director" class="text-content">电话: {{ item.telephone }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </router-layout>
</template>

<script>
import { organization_list, organization_listAll } from "@/api/organization";
import Nodata from "../public/nodata/Nodata"; // 导入暂无数据组件

export default {
  name: "component_name",
  components: { Nodata },
  data() {
    return {
      isNoData:false,
      images: [],
      dataList: [],
      listQuery: {
        current: 1,
        limit: 5,
        company_id: localStorage.getItem("companyId")
      }
    };
  },
  methods: {
    openLink(item) {
      this.$router.push({
        path: "/DetailList",
        query: {
          id: item.id,
          content: item
        }
      });
    },
    async initList() {
      this.listQuery.organization_id = 0;
      let res = await organization_list(this.listQuery);
      if (res.data.status == 100) {
        this.dataList = res.data.data.rows;
        if (!res.data.data.rows.length) {
          this.isNoData = true;
        }
      }
    },
    async bannerList() {
      let res = await organization_listAll(this.listQuery);
      if (res.data.status == 100) {
        this.images = res.data.data.rows;
      }
    }
  },
  created() {
    this.bannerList();
    this.initList();
  }
};
</script>
<style lang="scss" scoped>
.swipe-box {
  .img-box {
    width: 100%;
    overflow: hidden;
  }
}
.list-box {
  padding: 0 15px;
  border-top: 15px solid rgb(250, 250, 250);
}
.list {
  .content-box {
    padding: 15px 15px 15px 0;
  }
  .img-box {
    width: 60px;
    height: 60px;
    // border-radius: 50%;
    overflow: hidden;
    // box-shadow: 0px 0px 1px 1px #ccc;
    float: left;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
    }
  }
  .text-box {
    padding-left: 10px;
    font-size: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
  .other-text {
    padding-top: 10px;
    font-size: 12px;
    color: rgb(44, 176, 242);
  }
  .text-content {
    background-color: rgb(247, 252, 255);
    padding: 5px 10px;
    margin-right: 10px;
  }
}
</style>
